package Server.entity;


import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Data;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.GenericGenerator;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.*;

/**
 * Entity - 资源注册
 *
 * @author xvzhe
 * @version 0.1
 *
 */
@Data
@Entity
@EntityListeners(AuditingEntityListener.class)
@DynamicInsert
@DynamicUpdate
@Table(uniqueConstraints = {@UniqueConstraint(columnNames={"name"})})
public class DataResources {

    @Id
    @GeneratedValue(generator = "NumberIdProduce")
    @GenericGenerator(name="NumberIdProduce", strategy="Server.tool.NumberIdProduce")
    private String uuid;

    /*
    *
    * 资源名称
    * */
    @Column
    private String name;

    /*
    * 资源地址
    *
    * */
    @Column
    private String uri;

    /*
    *
    * 资源权限
    * */
    @Column
    private String permissions;

    /*
     * 资源类型
     *
     * */
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public enum Type {
        VIEW("页面"),
        TABLE("表头"),
        API("接口");
        Type(String display) {
            this.display = display;
        }
        private String display;

        public String getDisplay() {
            return display;
        }

        public void setDisplay(String display) {
            this.display = display;
        }
    }
    @Enumerated(EnumType.STRING)
    @Column
    private Type type;

    /*
     * 资源状态
     *
     * */
    @JsonFormat(shape = JsonFormat.Shape.OBJECT)
    public enum Status {
        NO("禁用"),
        YES("启用");
        Status(String display) {
            this.display = display;
        }
        private String display;

        public String getDisplay() {
            return display;
        }

        public void setDisplay(String display) {
            this.display = display;
        }
    }
    @Enumerated(EnumType.STRING)
    @Column
    private Status status;

    public String getUuid() {
        return uuid;
    }

    public void setUuid(String uuid) {
        this.uuid = uuid;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getUri() {
        return uri;
    }

    public void setUri(String uri) {
        this.uri = uri;
    }

    public String getPermissions() {
        return permissions;
    }

    public void setPermissions(String permissions) {
        this.permissions = permissions;
    }

    public Type getType() {
        return type;
    }

    public void setType(Type type) {
        this.type = type;
    }

    public Status getStatus() {
        return status;
    }

    public void setStatus(Status status) {
        this.status = status;
    }
}
